package ru.ifmo.croak.api;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Message.
 *
 * @author Roman Elizarov
 */
public class Message {
    private UUID id;
    private long time;
    private String author;
    private String text;

    /**
     * Returns unique message id.
     */
    public UUID getId() {
        return id;
    }

    /**
     * Sets unique message id.
     */
    public void setId(UUID id) {
        this.id = id;
    }

    /**
     * Returns message creation time.
     */
    public long getTime() {
        return time;
    }

    /**
     * Sets message creation time.
     */
    public void setTime(long time) {
        this.time = time;
    }

    /**
     * Returns message author.
     */
    public String getAuthor() {
        return author;
    }

    /**
     * Sets message author.
     */
    public void setAuthor(String author) {
        this.author = author;
    }

    /**
     * Returns message text.
     */
    public String getText() {
        return text;
    }

    /**
     * Sets message text.
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     * Creates a copy of this message.
     */
    @Override
    public Message clone() {
        try {
            return (Message) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Returns string representation of this message.
     */
    @Override
    public String toString() {
        return id + " " + new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date(time)) + " @" + author + ": " + text;
    }
}
